/**
 * 存储配置类
 */
import { configureStore } from '@reduxjs/toolkit'
import { persistStore, persistReducer } from "redux-persist"
import storage from "redux-persist/lib/storage"
//  存储机制，可换成其他机制，当前使用sessionStorage机制
// import storageSession from 'redux-persist/lib/storage/session';
//引入汇总之后的reducer
import reducers from './reducers'

//数据持久化配置,在localStorge中生成key为root的值
const persistConfig = {
    key: "root",
    storage,// 缓存机制
    // blacklist:['user']  //设置某个reducer数据不持久化，
}
//使用数据持久化，持久数据
const persistedReducer = persistReducer(persistConfig, reducers)
//创建store实例
export const store = configureStore({
    reducer:persistedReducer,
    middleware: (getDefaultMiddleware) =>
        getDefaultMiddleware({
            serializableCheck: false,
        }),
})

//导出
export const persistor = persistStore(store)
export type RootState = ReturnType<typeof store.getState>
export type AppDispatch = typeof store.dispatch

